package Chinese.Education.Identify.config;

import Chinese.Education.Identify.interceptor.LoginInterceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// @Configuration代表服务器启动的时候，自动初始化内部的配置参数，并且加载内存中
@Configuration
public class LoginInterceptorConfig implements WebMvcConfigurer {
    // 将登录拦截器配置到容器中
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")                // 拦截所有的请求，不管是页面、图片、接口服务等
                .excludePathPatterns("/",              // 放行指定的路径，可能是页面、图片、接口服务等
                        "/login.html",
                        "/login/StuLogin.html",
                        "/login/TeacherLogin.html",
                        "/stuUser/login",
                        "/teacherUser/login",
                        "/css/**",
                        "/img/**",
                        "/images/**",
                        "/favicon.ico",                // 放行网站图标
                        "/error",                      // 放行错误页面
                        "/jquery/**",
                        "/js/**",
                        "/layui/**",
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/v2/**",
                        "/swagger-ui.html/**");
    }

    // 配置视图跳转
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
//        registry.addViewController("/").setViewName("index");
//        registry.addViewController("/index.html").setViewName("index");
    }
}
